package com.ouc.entity;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Name: Frame
 * @Description: Frame产品
 * @Author: Mr.Tong
 */
@Data
public class Frame {
    //产品编码
    private String frameCode;
    //产品用到的线型（口径、材料）
    private String lineCode;
    //产品用到的形状（类型-圆形|长方形|三角形、属性-半径|长|宽|边一|边二|边三）
    private String shapeCode;
    //材料费
    private Double cost;
    //产品加工费
    private Double processCost;

    private List<CartItem> cartItems;
    @JsonDeserialize(using = Shape.ShapeDeserializer.class)
    private Shape shape;
    private Line line;

    public Double getCost() {
        if (cost == null) {
            cost = line.getUnitPrice() * shape.getPerimeter();
        }
        return cost;
    }

    public Double getUnitPrice() {
        return this.getCost() + this.getProcessCost();
    }

    public Double getProcessCost() {
        if (processCost == null) {
            processCost = shape.getArea() * shape.unitAreaPrice();
        }
        return processCost;
    }

}
